import { IsInt, IsString, Length, Max, Min } from "class-validator";
import { BaseEntity } from "@/common/BaseEntity";
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import SysMenuEntity from "../menu/Entity";

@Entity({
  name: "sys_menu_meta",
  orderBy: { createTime: "DESC" },
})
export default class SysMenuMetaEntity extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id: number;

  @Length(2, 10)
  @IsString()
  @Column({
    nullable: true,
  })
  public title: string;

  /**
   * 图标
   */
  @IsString()
  @Column({
    nullable: true,
  })
  public icon: string;

  rolePermissionList: string[];

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public hidden: number;

  @IsString()
  @Column({
    nullable: true,
  })
  activeMenu: string;

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public alwaysShow: number;

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public noCache: number;

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public breadcrumb: number;

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public affix: number;

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public noTagsView: number;

  @Max(1)
  @Min(0)
  @IsInt()
  @Column({
    nullable: true,
  })
  public canTo: number;

  @OneToOne(() => SysMenuEntity, (menu) => menu.meta)
  menu: SysMenuEntity;

  public static transform(plainObject: object): SysMenuMetaEntity {
    return super.baseTransform(SysMenuMetaEntity, plainObject);
  }
}
